package chpt06;

import java.util.Iterator;

public class CollectionDemo01 {

	public static void main(String[] args) {
		Course c1 = new Course("英语",3);
		Course c2 = new Course("体育",2);
		StudentV4 stu1 = new StudentV4("王星",18);
		StudentV4 stu2 = new StudentV4("陈妍",17);
		StudentV4 stu3 = new StudentV4("赵言",20);		
		StudentV4 stu4 = new StudentV4("张琳",21);
		StudentV4 stu5 = new StudentV4("李明",19);
		StudentV4 stu6 = new StudentV4("孙耀",20);
		// 英语有3名学生选修，向课程中增加3名学生信息，同时在学生属性中增加课程信息
		c1.getAllStudents().add(stu1);
		c1.getAllStudents().add(stu2);
		c1.getAllStudents().add(stu6);
		stu1.getAllCourses().add(c1);
		stu2.getAllCourses().add(c1);
		stu6.getAllCourses().add(c1);
		// 体育有4名学生选修，向课程中增加4名学生信息，同时在学生属性中增加课程信息
		c2.getAllStudents().add(stu2);
		c2.getAllStudents().add(stu3);
		c2.getAllStudents().add(stu4);
		c2.getAllStudents().add(stu5);
		stu2.getAllCourses().add(c2);
		stu3.getAllCourses().add(c2);
		stu4.getAllCourses().add(c2);
		stu5.getAllCourses().add(c2);
		// 输出一门课程的信息，并查看选修该门课程的学生
		System.out.println(c1);
		Iterator<StudentV4> iter1 = c1.getAllStudents().iterator();
		while(iter1.hasNext()) {
			System.out.println("\t|-" + iter1.next());
		}
		// 输出一个学生，并查看该学生选修的课程信息
		System.out.println(stu2);
		Iterator<Course> iter2 = stu2.getAllCourses().iterator();
		while(iter2.hasNext()) {
			System.out.println("\t|-" + iter2.next());					
		}
	}
}
